package dpss.commons;

import java.io.Serializable;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Vector;

/**
 * A server node
 * 
 * @author musab.mirza
 * 
 */
public class ServerNode implements Serializable {

	private InetSocketAddress socketAddress;
	private String group;
	private boolean leader;
	private int failCount;
	private boolean faulty;

	/**
	 * Constructor
	 * 
	 * @param ip
	 *            IP address of the node
	 * @param port
	 * @param name
	 *            Name of the node (asia, eur, na)
	 * @param leader
	 *            Leader or regular
	 * @param failCount
	 *            Total fails until now
	 */
	public ServerNode(InetSocketAddress socketAddress, String name,
			boolean leader, int failCount) {
		this.failCount = failCount;
		this.socketAddress = socketAddress;
		this.setLeader(leader);
		this.group = name;
		this.faulty = false;
	}

	public boolean isFaulty() {
		return faulty;
	}

	public void setFaulty(boolean faulty) {
		this.faulty = faulty;
	}

	public InetSocketAddress getSocketAddress() {
		return socketAddress;
	}

	public void setSocketAddress(InetSocketAddress socketAddress) {
		this.socketAddress = socketAddress;
	}

	public String getGroup() {
		return group;
	}

	public void setGroup(String group) {
		this.group = group;
	}

	public int getFailCount() {
		return failCount;
	}

	public void setFailCount(int failCount) {
		this.failCount = failCount;
	}

	public boolean isLeader() {
		return leader;
	}

	public void setLeader(boolean leader) {
		this.leader = leader;
	}

	public String toString() {
		return "Address: " + socketAddress.toString() + ", group: " + group
				+ ", isLeader: " + leader + ", failCount: " + failCount
				+ ", faulty: " + faulty;
	}

	public void increaseFailCount() {
		failCount++;
	}

}
